<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>奖品规则</title>
<import type='css' file="css.main" />
<load href="__PUBLIC__/js/jquery-1.9.1.min.js" />
<import type='js' file="js.main" />
<import type='css' file="css.awardstyle" />
</head>

<body>
<div class="main-frame" style="padding-top:0px;">
	<!-- 图片资源开始 -->
	<div class="floatBackground" id="floatBackground" style="display: none;">
		<div class="bounced">
			<label class="closeImgResurces">X</label>
			<iframe id="imgResourcesiframe" src="{:rtrim(U('Upload/index'),'.html')}" width="750" height="465" frameborder="0" scrolling="auto"></iframe>
		</div>
	</div>
	<!-- 图片资源结束 -->

	<div class="position">华人码 > 奖品规则</div>
	<div class="table-list addruleinfo" style="border:none; background-color:#00A388;">
		<div class="infos">
			<div class="infobg">
				<label>规则标题：</label><input type="text" name="ruletitle" style="margin-right:24px;" />
				<label>规则备注：</label><input type="text" name="ruledes" />
			</div>
			<input type="button" value="添加规则" class="addrule"/>	
		</div>
	</div>

	<table width="100%" border="1" cellspacing="0" cellpadding="0" class="indextable" style="border:none;">
		<tr class="th-bg ths-bgs" style="background-color: #f7f7f7;">
			<th width="8%"></th>
			<th width="16%">奖品名称</th>
			<th width="12%">奖品数量</th>
			<th width="15%">奖品类型</th>
			<th width="35%">奖品参数</th>
			<th width="12%">操作</th>
		</tr>
	</table>
	<volist name="awardlist" id="v">
	<div class="table-list tablelists" style="margin-bottom:10px; width:auto;">
	 <table width="100%" border="1" cellspacing="0" cellpadding="0" class="indextable">
		    <tr class="th-bg">
		      <th width="4%" colspan="6" class="ruletitle"><a class="ruledelete" v="{$v['id']}">删除规则</a>&nbsp;&nbsp; {$v['typename']} （说明：{$v['awarddes']}）<time>{$v['awarddate']}</time></th>
	        </tr>
			 <volist name="v['info']" id="data" key="k">
				<tr class="tr-line trc{$data['id']} awardlist">
				  <form action="{:U('editaward',array('id'=>$v['id']))}" name="editform{$v['id']}" id="editform{$v['id']}" method="post">
				  <input type="hidden" class="inputv" name="id" value="{$data['id']}" />
				  <td width="8%">奖项{$k}：</td>
				  <td width="16%"><input class="inputb" disabled type="text" name="awardname" placeholder="奖项名称" value="{$data.awardname}"/></td>
				  <td width="12%"><input class="inputb" disabled type="text" name="awardnum" placeholder="奖品个数" style="width:80px;" value="<if condition="($data['awardnum'] neq '') and ($data['awardnum'] neq 0)">{$data.awardnum}<else />-</if>"/></td>
				  <td width="15%">
					  <select name="awardkind1" class="inputb" disabled>
					  	 <volist name="awardtype" id="telv">
					 	 	<option value="{$i}" <if condition="$data['awardkind'] eq $i">selected</if>>{$telv[$i]}</option>
					 	 </volist>
					  </select>
					  <input type="hidden" class="inputv" name="awardkind" value="{$data['awardkind']}" />
				  </td>
				  <td width="35%" class="imginfo">
					  <if condition="($data['awardkind'] eq 2) and ($data['awardimg'] neq '')">
						  <img src="{$data['awardimg']}" height="50" />
                          <div class="uploadimg" style="display:none;">
                              <input type="text" name="awardimg" id="awardimg{$data['id']}" value="{$data['awardimg']}" class="inputc sult" placeholder="缩略图">
                              <a class="browse" f='awardimg{$data['id']}'>浏览···</a>
                          </div>
					  </if>
					  <if condition="$data['awardkind'] eq 3">
						  <div class="moneyscope">
							  <input class="inputb u_hbmoney" type="text" name="u_hbmin" disabled placeholder="最小金额" value="{$data.u_hbmin}" /> - <input class="inputb u_hbmoney" type="text" name="u_hbmax" disabled placeholder="最大金额" value="{$data.u_hbmax}" /> &nbsp;&nbsp;单位：元
						  </div>
					  </if>
					  <if condition="$data['awardkind'] eq 5">
						  <div class="teltopup">
						 	 <select class="inputb" style="width:auto;" name="awardteltopup" disabled>
						 	 	<volist name="teltopup" id="telv" key="teli">
						 	 		<option value="{$telv[$teli]}" <if condition="$data['awardteltopup'] eq $telv[$teli]">selected</if>>{$telv[$teli]}元</option>
						 	 	</volist>
						 	 </select>
						 </div>
				 	  </if>
				 	  <if condition="$data['awardkind'] eq 4">
					 	  <div class="editflow flowl">
						 	<foreach name="flowl" item="flow" key="i">
						 	<span>
						 		<input type="hidden" name="operator_{$flow['companytype']}" value="{$flow['companytype']}">
						 		<label>{$flow['company']}：</label>
						 		<foreach name="flow['flows']" item="flows" key="i1">
						 			<input type="checkbox" disabled value="{$flows['id']}" <in name="flows['id']" value="$data['flowinfo']">checked="checked"</in> name='<if condition="$flow['companytype'] eq 1">lt_eck[]<elseif condition="$flow['companytype'] eq 2"/>yd_eck[]<elseif condition="$flow['companytype'] eq 3"/>dx_eck[]</if>'>{$flows['p']}
						 		</foreach>
						 	</span>
						 	</foreach>				 	 
						  </div>
					  </if>
					  <if condition="$data['awardkind'] eq 6">
						  <div class="refuel">
						 	<input type="text" name="refuel" value="{$data.refuel}" placeholder="加油卡金额" class="inputb textrefuel" disabled> <span>单位：元（支持中石化、中石油加油卡）</span>		 	 
						  </div>
					  </if>

				  </td>
				  <td width="12%">
					  <a class="edit cedit" v="{$data['id']}" xn="{$data['awardkind']}">修改</a>
					  <input type="submit" value="保存" class="edit awardsave" />
					  <a class="delete" v="{$data['id']}">删除</a>
				  </td>
				  </form>
				</tr>
			 </volist>
		 <tr class="tr-line">
			 <form action="{:U('addaward',array('id'=>$v['id']))}" name="form{$v['id']}" id="form{$v['id']}" method="post">
		     <input type="hidden" class="inputv" name="newimginfo" value="" />
		     <input type="hidden" class="inputv" name="typeid" value="{$v['id']}" />
			 <td width="8%" style="background-color:#fff;">奖项<?php echo count($v['info'])+1 ;?>：</td>
			 <td width="16%"><input class="inputc inputv" type="text" name="awardname" placeholder="奖项名称" /></td>
			 <td width="12%"><input class="inputc addawardnum inputv" type="text" name="awardnum" placeholder="奖品个数" style="width:80px;" /></td>
			 <td width="15%">
				 <select name="awardkind" class="inputc">
				 	 <volist name="awardtype" id="telv">
				 	 	<option value="{$i}"{$telv['selected']}>{$telv[$i]}</option>
				 	 </volist>
				 </select>
			 </td>
			 <td width="35%" class="addawardimg">
				 <div class="uploadimg"><input type="text" name="awardimg" id="awardimg{$v['id']}" class="inputc sult inputv" placeholder="缩略图"><a class="browse" f='awardimg{$v['id']}'>浏览···</a></div>
			 	 <div class="moneyscope" style="display: none;">
					 <input type="text" name="u_hbmin" placeholder="最小金额" class="u_hbmoney inputv" /> - <input type="text" name="u_hbmax" placeholder="最大金额" class="u_hbmoney inputv" /> &nbsp;&nbsp;单位：元
				 </div>
				 <div class="teltopup" style="display: none;">
				 	 <select name="awardteltopup">
				 	 	<volist name="teltopup" id="telv">
				 	 		<option value="{$telv[$i]}"{$telv['selected']}>{$telv[$i]}元</option>
				 	 	</volist>
				 	 </select>
				 </div>
				 <div class="flowl" style="display: none;">
				 	<volist name="flowl" id="flow" key="i">
				 	<span>
				 		<input type="hidden" name="operator_{$flow['companytype']}" value="{$flow['companytype']}">
				 		<label>{$flow['company']}：</label>
				 		<volist name="flow.flows" id="flows" key="i1">
				 			<input type="checkbox" value="{$flows['id']}" name='<if condition="$flow['companytype'] eq 1">lt_eck[]<elseif condition="$flow['companytype'] eq 2"/>yd_eck[]<elseif condition="$flow['companytype'] eq 3"/>dx_eck[]</if>'>{$flows['p']}
				 		</volist>
				 	</span>
				 	</volist>				 	 
				 </div>
				 <div class="refuel" style="display: none;">
				 	<input type="text" name="refuel" placeholder="加油卡金额" class="textrefuel"> <span>单位：元（支持中石化、中石油加油卡）</span>		 	 
				 </div>

			 </td>
			 <td width="12%"><input type="submit" value="添加" class="add" /></td>
			 </form>
		 </tr>
      </table>
    </div>
	</volist>
	<if condition="$page neq 1"><div class="page">{$page}</div></if>
</div>
<script type="text/javascript">
	$(function(){
		$(".tablelists:last").css({"margin-bottom":"36px"});
		//删除规则
		$("a.ruledelete").each(function(index,element){
			var t = $(this);
			t.click(function(){
				var id = $(this).attr('v');
				var r=confirm("想好！确定要删除吗？");
				if(r){
					var savetel_url = "{:U('deleterule')}";
					var teldata = {"id":id,random:Math.random()};
					$.ajax({
						url:savetel_url,
						data:teldata,
						type:"POST",
						dataType:"html",
						success:function (data){
							if(data==1){
								//alert('删除成功');
								location.reload()
							}else if(data==2){
								alert('当前规则下有奖品设置，请先删除奖品设置再进行删除当前规则');
							}else{
								alert('删除失败');
							}
						}
					});
				}
			})
		})
		//添加规则标题
		$("input.addrule").click(function(){
			var ruletitle = $("input[name='ruletitle']").val();
			var ruledes = $("input[name='ruledes']").val();
			if($.trim(ruletitle)!=''){
				var savetel_url = "{:U('addtitle')}";
				var teldata = {"ruletitle":ruletitle,"ruledes":ruledes,random:Math.random()};
				$.ajax({
					url:savetel_url,
					data:teldata,
					type:"POST",
					dataType:"html",
					success:function (data){
						if(data==1){
							location.reload()
						}else{
							alert('添加失败');
						}
					}
				});
			}else{
				alert('规则标题不能为空');
				$("input[name='ruletitle']").focus();
			}
		})

		
		$("select.inputc").each(function(index, element1){
			$(this).change(function(){
				$("input.addawardnum:eq("+index+")").show();
				var t = $(this).val();
				if(t==3){
					$("td.addawardimg:eq("+index+") .uploadimg input.inputv").val(null);
					$("td.addawardimg:eq("+index+") div").hide();
					$("td.addawardimg:eq("+index+") div.moneyscope").show();
				}else if(t==1){
					$("input.addawardnum:eq("+index+")").val(null);
					$("td.addawardimg:eq("+index+") div input.inputv").val(null);
					$("input.addawardnum:eq("+index+")").hide();
					$("td.addawardimg:eq("+index+") div").hide();
				}else if(t==5){
					$("input.addawardnum:eq("+index+")").val(null);
					$("td.addawardimg:eq("+index+") div input.inputv").val(null);
					$("td.addawardimg:eq("+index+") div").hide();
					$("td.addawardimg:eq("+index+") div.teltopup").show();
				}else if(t==4){
					$("input.addawardnum:eq("+index+")").val(null);
					$("td.addawardimg div input.inputv").val(null);
					$("td.addawardimg:eq("+index+") div").hide();
					$("td.addawardimg:eq("+index+") div.flowl").show();
				}else if(t==6){
					$("input.addawardnum:eq("+index+")").val(null);
					$("td.addawardimg div input.inputv").val(null);
					$("td.addawardimg:eq("+index+") div").hide();
					$("td.addawardimg:eq("+index+") div.refuel").show();
				}else{
					$("td.addawardimg:eq("+index+") div input.inputv").val(null);
					$("td.addawardimg:eq("+index+") div").hide();
					$("td.addawardimg:eq("+index+") div.uploadimg").show();					
				}
			})
		})
		//删除
		$("a.delete").each(function(index, element1){
			var t = $(this);
			t.click(function(){
				var id = $(this).attr('v');
				var r=confirm("想好！确定要删除吗？");
				if (r==true){
					var savetel_url = "{:U('deleteaward')}";
					var teldata = {"id":id,random:Math.random()};
					$.ajax({
						url:savetel_url,
						data:teldata,
						type:"POST",
						dataType:"html",
						success:function (data){
							if(data==1){
								$("tr.awardlist:eq("+index+")").remove();
							}else{
								alert('删除失败');
							}
						}
					});
				}
			})
		})

		$("a.cedit").each(function(index,element){
			var t = $(this);
			t.click(function(){
				$(this).hide();
				$(".awardsave:eq("+index+")").show();

				var id = $(this).attr('v');
				var t1 = $("tr.trc"+id);
				t1.find('input').removeClass('inputb').addClass('inputc').removeAttr('disabled');
				t1.find("select[name='awardteltopup']").removeAttr("disabled");
				t1.find('select').removeClass('inputb').addClass('inputc');
				t1.find('td.imginfo img').hide();
				t1.find('td.imginfo div.uploadimg').show();
			})
		})

		function writeObj(obj){
			var description = "";
			for(var i in obj){
				var property=obj[i];
				description+=i+" = "+property+"\n";
			}
			alert(description);
		}
		
	})
</script>
</body>
</html>
